package com.daoeping.action;

import java.util.List;

import com.daoeping.data.Bsc_address;
import com.daoeping.data.Cop_companyinfo;
import com.daoeping.data.Usr_education;
import com.daoeping.data.Usr_projectexperience;
import com.daoeping.data.Usr_userbasicinfo;
import com.daoeping.data.Usr_workexperience;
import com.daoeping.domain.Usr_userProduction;
import com.daoeping.service.Bsc_addressService;
import com.daoeping.service.Cop_companyinfoService;
import com.daoeping.service.Usr_UserbasicinfoService;
import com.daoeping.service.Usr_educationService;
import com.daoeping.service.Usr_projectexperienceService;
import com.daoeping.service.Usr_workexperienceService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class Usr_UserbasicinfoAction extends ActionSupport{
	
	private Usr_userbasicinfo usr_userbasicinfo;
	private Bsc_address liveAddress;
	private Bsc_address registeredAddress;
	
	private Usr_UserbasicinfoService usr_UserbasicinfoService;
	private Bsc_addressService bsc_addressService;
	
	private Usr_workexperienceService usr_workexperienceService;
	private Usr_projectexperienceService usr_projectexperienceService;
	private Usr_educationService usr_educationService;

	public Usr_userbasicinfo getUsr_userbasicinfo() {
		return usr_userbasicinfo;
	}

	public void setUsr_userbasicinfo(Usr_userbasicinfo usr_userbasicinfo) {
		this.usr_userbasicinfo = usr_userbasicinfo;
	}
	
	public Usr_UserbasicinfoService getUsr_UserbasicinfoService() {
		return usr_UserbasicinfoService;
	}

	public void setUsr_UserbasicinfoService(
			Usr_UserbasicinfoService usr_UserbasicinfoService) {
		this.usr_UserbasicinfoService = usr_UserbasicinfoService;
	}

	public Bsc_address getLiveAddress() {
		return liveAddress;
	}

	public void setLiveAddress(Bsc_address liveAddress) {
		this.liveAddress = liveAddress;
	}

	public Bsc_address getRegisteredAddress() {
		return registeredAddress;
	}

	public void setRegisteredAddress(Bsc_address registeredAddress) {
		this.registeredAddress = registeredAddress;
	}

	public Bsc_addressService getBsc_addressService() {
		return bsc_addressService;
	}

	public void setBsc_addressService(Bsc_addressService bsc_addressService) {
		this.bsc_addressService = bsc_addressService;
	}

	public Usr_workexperienceService getUsr_workexperienceService() {
		return usr_workexperienceService;
	}

	public void setUsr_workexperienceService(
			Usr_workexperienceService usr_workexperienceService) {
		this.usr_workexperienceService = usr_workexperienceService;
	}

	public Usr_projectexperienceService getUsr_projectexperienceService() {
		return usr_projectexperienceService;
	}

	public void setUsr_projectexperienceService(
			Usr_projectexperienceService usr_projectexperienceService) {
		this.usr_projectexperienceService = usr_projectexperienceService;
	}

	public Usr_educationService getUsr_educationService() {
		return usr_educationService;
	}

	public void setUsr_educationService(Usr_educationService usr_educationService) {
		this.usr_educationService = usr_educationService;
	}

	public String addUsr_Userbasicinfo(){
		this.bsc_addressService.addBsc_address(liveAddress);
		this.bsc_addressService.addBsc_address(registeredAddress);
		
		usr_userbasicinfo.setBsc_addressByLiveAddressId(liveAddress);
		usr_userbasicinfo.setBsc_addressByRegisteredAddressId(registeredAddress);
		
		this.usr_UserbasicinfoService.addUsr_userbasicinfo(usr_userbasicinfo);		
		return "addUsr_Userbasicinfo";
	}
	
	public String editUsr_Userbasicinfo(){
		this.bsc_addressService.editBsc_address(liveAddress);
		this.bsc_addressService.editBsc_address(registeredAddress);
		
		usr_userbasicinfo.setBsc_addressByLiveAddressId(liveAddress);
		usr_userbasicinfo.setBsc_addressByRegisteredAddressId(registeredAddress);
		
		this.usr_UserbasicinfoService.editUsr_userbasicinfo(usr_userbasicinfo);
		
		return "editUsr_Userbasicinfo";
	}
	
	public String findUsr_userbasicinfoByUserId(){
		//int user_id = usr_userbasicinfo.getUsr_user().getId();	
		int user_id = 1;	
		Usr_userbasicinfo myUsr_userbasicinfo = ((List<Usr_userbasicinfo>)this.usr_UserbasicinfoService.findUsr_userbasicinfoByUserId(user_id)).get(0);
		ActionContext.getContext().put("myUsr_userbasicinfo", myUsr_userbasicinfo);
		
		return "findUsr_userbasicinfoByUserId";
	}

	public String findUsr_userbasicinfoById(){
		int id = usr_userbasicinfo.getId();	
		Usr_userbasicinfo myUsr_userbasicinfo = ((List<Usr_userbasicinfo>)this.usr_UserbasicinfoService.findUsr_userbasicinfoById(id)).get(0);
		ActionContext.getContext().put("myUsr_userbasicinfo", myUsr_userbasicinfo);
		
		return "findUsr_userbasicinfoById";
	}
	
	public String findUsrAllInfoByUserId(){
		int user_id,work_exp_id,i;
		List<Usr_projectexperience> myUsr_projectexperience = null;
		
		//Usr_userbasicinfo
		user_id = usr_userbasicinfo.getUsr_user().getId();	
		Usr_userbasicinfo myUsr_userbasicinfo = ((List<Usr_userbasicinfo>)this.usr_UserbasicinfoService.findUsr_userbasicinfoByUserId(user_id)).get(0);
		ActionContext.getContext().put("myUsr_userbasicinfo", myUsr_userbasicinfo);
		
		//Usr_workexperience
		List<Usr_workexperience> myUsr_workexperience = (List<Usr_workexperience>)this.usr_workexperienceService.findUsr_workexperienceByUserId(user_id);
		ActionContext.getContext().put("myUsr_workexperience", myUsr_workexperience);
		
		for(i=0;i<myUsr_workexperience.size();i++){
			work_exp_id = myUsr_workexperience.get(i).getId();	
			myUsr_projectexperience = (List<Usr_projectexperience>) this.usr_projectexperienceService.findUsr_projectexperienceByWorkexpId(work_exp_id);		
			ActionContext.getContext().put("myUsr_projectexperience", myUsr_projectexperience);
		}
		

		//Usr_education
		List<Usr_education> myUsr_education = (List<Usr_education>) this.usr_educationService.findUsr_educationByUserId(user_id);
		ActionContext.getContext().put("myUsr_education", myUsr_education);
		
		return "findUsrAllInfoByUserId";
	}
	
	
}
